// 基础的公共配置
let baseConfig = {
  // 环境变量
  ENV: ENV,
  // 系统名字
  appName: "房县住房供应链管理平台",
  // 底部版权文本
  footerText: "版权所有 © 2018",
  // 是否需要登陆
  // isLogin: true,
  isLogin: true,
  // 是否需要填验证码
  isIdentifyCode: false,
  // 登录cookie超时 ，单位天
  loginTimeout: 1,
  // 请求超时
  reqTimeout: 150000,
  // reqTimeout: 15000,
  // 统一表格分页配置1
  largePageSizeList: ["10", "20", "50", "100"],
  // 统一表格分页配置2
  smallPageSizeList: ["10", "20", "50", "100", "200", "500"],
  // 默认路由
  homePath: "/",
  // 默认图片大小
  imgSize: "80",
  // 登陆之后是否跳转页面，true: 跳转至 配置的homePath; false: 跳转至/
  isRedirect: true,
  // 是否需要切换组织
  isMultiOrg: false,
  //是否需要消息通知
  isMsgNotify: false,
  //富文本
  baseURL: "https://points.dtyunxi.com/",
  mideaCommission:'midea-commission',
  //地图配置
  mapCfg: {
    webServkey: "7e61745f0e479ccedbcc70071ec3f690",
    webJSServkey: "d10c80d91984f09f2c6d22e1837a0b4b",
  },
  //cookie key
  cookie: {
    userInfo: "user_midea_info",
    auth: "user_midea_auth",
    userName: "user_midea_name",
    userId: "user_midea_accountId",
    regionId: "user_midea_regionId",
    // userType: 'user_type',
    // userForm: 'user_form',
    // loginType: 'login_type',
  },
  // 每个接口都需要传的Application-Key
  appKey: "cube",
  //是否显示静态菜单
  // isStaticMenu: false,
  isStaticMenu: ENV == "test" ? true : false,
  //是否显示静态权限按钮
  // isFlagBtn:false,
  isFlagBtn: ENV == "loc" ? true : false,
  // 接口主机地址
  baseUrl: "",
  //h5链接

  //列表页一些配置
  listConfig: {
    //表格是否添加滚动条td上限
    scrollTd: 5,
    //表格滚动配置
    tableScroll: { x: 1200 },
    //处理表格是否有滚动条
    tableTdLength: (e) => {
      let scroll = {};
      if (e.length > baseConf.listConfig.scrollTd) {
        scroll = { x: 1200 };
      }
      //return scroll;
      return {};
    },
    //处理表格头部信息
    columns: (e) => {
      let widthName = {
        //日期
        time: "150px",
        //手机
        phone: "115px",
      };
      e.map((item) => {
        //如果是日期，宽度100
        for (let i in widthName) {
          if (item["name"] == i) {
            item.width = widthName[i];
          }
        }
        if (item["title"] == "序号") {
          item.width = "65px";
        }
      });
      return e;
    },
    //搜索框布局
    searchCol: {
      xs: { span: 24 },
      md: { span: 12 },
      lg: { span: 8 },
      xl: { span: 8 },
    },
    searchFormItem: {
      labelCol: { span: 8 },
      wrapperCol: { span: 16 },
    },
  },
  // 公共的api请求
  requestApiUrl: {
    //获取手机验证码
    phoneCode: `pearlriver-sys-application/api/v1/pearlriver/sms/send`,
    //修改登录密码
    updatedPassword: `pearlriver-sys-application/api/v1/pearlriver/comm/user/password/update`,
    //忘记登录密码
    forgetPassword: `smartsales-sys-application/api/v1/sys/user/password/forget`,
    // 查询角色操作按钮
    queryAuth: `smartsales-sys-application//api/admin/user/getRoleRes`,
    // 查询菜单权限
    queryAuthPath: `admin/permissionAdmin/queryPermission`,
    // 获取图形验证码
    getValidateImg: `users/authoriz/verify/img`,
    //注销
    delCacheUser: `admin/login/logout`,
    //获取组织
    userOrg: `smartsales-sys-application/api/v1/sys/user/unit/list`,
    //组织切换保存
    updateSelCurOrg: `smartsales-sys-application/api/v1/sys/user/change/unitid`,
    //获取用户详情
    getUserDetail: `pearlriver-sys-application/api/v1/pearlriver/user/get/detail`,
    // 上传签名url
    getPolicyUrl: `admin/oss/token`,
    //登录
    loginUrl: `admin/login/login4A`,
    // 上传图片
    uploadUrl: `http://www.dtyunxi.com/dtyunxi-marketplace-mgmt/api/v1/admin/news/upload`,
  },
  mock: false,
};

// 获得应用的key
const getAppKey = (env) => {
  // let path = window.location.href.split('#')[0], domainPath;
  // if('loc' === '' + env || 'dev' === '' + env){
  //   domainPath = 'https://wxdev.dtyunxi.cn/isales/dev/isales-operations-web-pc/';
  // }else{
  //   domainPath = path;
  // }
  // return encodeURIComponent(domainPath);
  return "cube";
};
// 根据不同环境变量，不同的配置
let envConfig = {
  loc: {
    // baseUrl: '/',
    // baseUrl: 'http://10.73.155.25:8763/',
    // baseUrl: 'http://10.73.156.7:8763/',
    // mock: false,
    // baseUrl: 'https://admin-zmzj-dev.mideazy.com/',//dev  访问路径 https://admin-zmzj-dev.mideazy.com/html
    // baseUrl: 'https://admin-zmzj-test.mideazy.com/',//test
    // baseUrl: 'https://admin-zmzj.mideazy.com/',//prod
    // baseUrl: 'https://admin-zmzj-uat.mideazy.com/',//uat
    mock: false,
    appKey: getAppKey("loc"),
    h5Url: "https://app-zmzj-uat.mideazy.com/h5/admin/",
    shenzhenUrl: "https://zmzj-test.oss-cn-shenzhen.aliyuncs.com",
    appName: "房县住房供应链平台",
    zysqAppKey: "wx200ae2633309d211",
    zmzjAppKey: "wx22f5910658b0e74b",
    zysqAppsecret: "596392eea6df85065deb488d06e273de",
    // hktServer1:'http://10.73.156.97:8763/',
    // hktServer:'http://10.73.155.25:8763/',
    hktServer: `https://admin-zmzj-uat.mideazy.com/zituo-admin`,
    aheadPlan: `https://api-zmzj-uat.mideazy.com/ahead-plan/`,
    mideaCommission:`https://admin-cloud-uat.mideazy.com/midea-commission/`,
    qvpHost:`https://aode-web.zhkhl.com/`
  },
  dev: {
    baseUrl: "/",
    mock: false,
    appKey: getAppKey("dev"),
    zmzjAppKey: "wx22f5910658b0e74b",
    appName: "数字营销运营平台-开发环境",
  },
  test: {
    baseUrl: "/",
    mock: false,
    appKey: getAppKey("test"),
    appName: "数字营销运营平台-test测试环境",
    zysqAppKey: "wx6b8145f4c1979877",
    zmzjAppKey: "wx22f5910658b0e74b",
    zysqAppsecret: "98a30bc1bd007cfca4eca4acb3be3a03",
    h5Url: "https://app-zmzj-uat.mideazy.com/h5/admin/",
    shenzhenUrl: "https://zmzj-test.oss-cn-shenzhen.aliyuncs.com",
    hktServer: `https://admin-zmzj-uat.mideazy.com/zituo-admin`,
    aheadPlan: `https://api-zmzj-uat.mideazy.com/ahead-plan/`,
    mideaCommission:`https://admin-cloud-uat.mideazy.com/midea-commission/`,
    // qvpHost:`https://aode-web.zhkhl.com/`
    qvpHost:`https://aode-web.zhkhl.com/`
  },
  sit: {
    baseUrl: "/",
    mock: false,
    appKey: getAppKey("sit"),
    h5Url: "https://app-zmzj-uat.mideazy.com/h5/admin/",
    appName: "数字营销运营平台-sit测试环境",
    zysqAppKey: "wx6b8145f4c1979877",
    zmzjAppKey: "wx22f5910658b0e74b",
    zysqAppsecret: "98a30bc1bd007cfca4eca4acb3be3a03",
  },
  uat: {
    baseUrl: "/",
    mock: false,
    appKey: getAppKey("uat"),
    h5Url: "https://app-zmzj-uat.mideazy.com/h5/admin/",
    shenzhenUrl: "https://zmzj-test.oss-cn-shenzhen.aliyuncs.com",
    appName: "数字营销运营平台-uat测试环境",
    zysqAppKey: "wx200ae2633309d211",
    zmzjAppKey: "wx22f5910658b0e74b",
    zysqAppsecret: "596392eea6df85065deb488d06e273de",
  },
  prod: {
    baseUrl: "/",
    mock: false,
    appKey: getAppKey("prod"),
    h5Url: "https://www.hbfxgyl.com/h5/admin/",
    shenzhenUrl: "https://zmzj.oss-cn-shenzhen.aliyuncs.com",
    appName: "房县住房供应链平台",
    zysqAppKey: "wx7805eeb108234548",
    zmzjAppKey: "wxf435566cf9956939",
    zysqAppsecret: "8c24da99b751504beb75149b912d1466",
    aheadPlan: `https://www.hbfxgyl.com/ahead-plan/`,
    mideaCommission:`https://www.hbfxgyl.com/midea-commission/`,
    qvpHost:`https://qvp.hbfxgyl.com/`
    // qvpHost:`https://qvp.zhkhl.com/`
  },
};
// debugger
// 合并配置
let config = Object.assign(baseConfig, envConfig[baseConfig.ENV]);

/**
 * 获得api接口地址
 * @param  {String} url    接口地址
 * @param  {Object} config 基础配置信息
 * @return {String}        转换过的接口地址
 */

const getApiAppName = function (url) {
  if (!url) {
    return;
  } else if (url.indexOf("http") >= 0) {
    return url;
  }

  let str = "";
  // 本机开发环境，则当前assets/mock下面的json
  if (config.mock && (config.ENV == "loc" || config.ENV === "dev")) {
    return (
      document.location.origin +
      document.location.pathname +
      "/assets/mock/" +
      url.replace(/\//g, "-") +
      ".json"
    );

    // 其它环境，则读取真实应用的接口
  } else {
    // url到应用的映射
    let apiAppName = {
      "smartsales/trade": "smartsales-trade-application",
      "smartsales/mgmt": "smartsales-mgmt-application",
      "yundt/mgmt": "yundt-application-mgmt",
    };
    for (let key in apiAppName) {
      if (url.indexOf(key) >= 0) {
        str = apiAppName[key];
      }
    }
    let version = "api/v1";
    let speUrl = [
      "admin/oss/token",
      "admin/login/login4A",
      "admin/login/logout",
    ];

    //美的项目api url直接使用相对路径，不需要拼接
    // if (speUrl.includes(url)) {
    //   return `${config.baseUrl}/${url}`
    // } else {
    //   return `${config.baseUrl}/${version}/${url}`
    // }
    if (config.baseUrl === "/") {
      return url.charAt(0) === "/"
        ? `${location.origin}${url}`
        : `${location.origin}/${url}`;
    } else {
      return `${config.baseUrl}${url}`;
    }
  }
};

// 拼接接口所需域名和服务名，只需要输入接口名即可  如 yundt/mgmt/item/list-by-page，也不要加斜杆开始，
// 如果接口以http开头，则不会进拼接，而是保留原样
// 如果是mock，则会去assets/mock请求同名json，但/会被替换为-   如  yundt-mgmt-item-list-by-page.js
config.apiAppName = getApiAppName;

export default config;
